package com.zhy_9.maidu.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.zhy_9.maidu.R;
import com.zhy_9.maidu.model.HomeBean;

import java.util.List;

/**
 * Created by ZHY_9 on 2017/7/11.
 */

public class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.HomeHolder> {

    private List<HomeBean.News> data;
    Context context;

    public HomeAdapter(List<HomeBean.News> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public HomeHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_home, null);
        HomeHolder holder = new HomeHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(HomeHolder holder, int position) {

        holder.name.setText(data.get(position).getGoods_name());
        Picasso.with(context).load("http://172.16.60.85/" + data.get(position).getGoods_img()).into(holder.img);
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    class HomeHolder extends RecyclerView.ViewHolder{

        ImageView img;
        TextView name;

        public HomeHolder(View itemView) {
            super(itemView);
            img = (ImageView) itemView.findViewById(R.id.img);
            name = (TextView) itemView.findViewById(R.id.name);
        }
    }
}
